package top.du1888.ai.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import top.du1888.ai.domain.TCar;
import top.du1888.ai.domain.User;
import top.du1888.ai.service.CarService;

import java.util.List;

@Controller
public class HelloController {
    private static final Logger log = LoggerFactory.getLogger(HelloController.class);
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    public CarService carService;


    @RequestMapping("/hello")
    @ResponseBody
    public List<TCar> hello(){
//        log.info("删除id为{}的数据","123456");
//        User user = new User(1,"小明", 18, "香港");
//        redisTemplate.opsForValue().set("user", JSON.toJSONString(user));
//        log.info(redisTemplate.opsForValue().get("user").toString());
        List<TCar> carList = carService.getAll();
        return carList;
    }


    @RequestMapping("/getCarById")
    @ResponseBody
    public TCar getCarById(@RequestParam(name="id") int id){
        return carService.getCarById(id);
    }


    @RequestMapping("/getUserByParam")
    @ResponseBody
    public TCar getUserByParam(@RequestParam(name="id") int id){
        return carService.getUserByParam(id);
    }
}
